package com.kexio.auth.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * MyBatis-Plus智能配置属性
 * 
 * 🎛️ 统一的配置入口，支持细粒度控制每个拦截器的行为
 * 
 * 配置示例：
 * ```yaml
 * kexio:
 *   auth:
 *     mybatis-plus:
 *       enabled: true                    # 总开关
 *       pagination:
 *         enabled: true                  # 分页拦截器开关
 *         max-limit: 1000               # 最大分页限制
 *         overflow: false               # 溢出处理
 *       optimistic-lock:
 *         enabled: true                  # 乐观锁拦截器开关
 *       tenant:
 *         enabled: auto                  # 租户拦截器：auto/true/false
 *       meta-handler:
 *         enabled: true                  # 字段自动填充开关
 * ```
 * 
 * @author Kexio Team
 * @since 3.0.0
 */
@ConfigurationProperties(prefix = "kexio.auth.mybatis-plus")
public class MybatisPlusProperties {
    
    /**
     * MyBatis-Plus功能总开关
     */
    private boolean enabled = true;
    
    /**
     * 分页拦截器配置
     */
    private PaginationConfig pagination = new PaginationConfig();
    
    /**
     * 乐观锁拦截器配置
     */
    private OptimisticLockConfig optimisticLock = new OptimisticLockConfig();
    
    /**
     * 租户拦截器配置
     */
    private TenantConfig tenant = new TenantConfig();
    
    /**
     * 字段自动填充配置
     */
    private MetaHandlerConfig metaHandler = new MetaHandlerConfig();
    
    /**
     * 数据权限拦截器配置
     */
    private DataScopeConfig dataScope = new DataScopeConfig();
    
    /**
     * 分页拦截器配置
     */
    public static class PaginationConfig {
        /**
         * 是否启用分页拦截器
         */
        private boolean enabled = true;
        
        /**
         * 最大分页限制（防止大数据量查询）
         */
        private long maxLimit = 1000L;
        
        /**
         * 溢出处理：true-回到首页，false-抛异常
         */
        private boolean overflow = false;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public long getMaxLimit() { return maxLimit; }
        public void setMaxLimit(long maxLimit) { this.maxLimit = maxLimit; }
        
        public boolean isOverflow() { return overflow; }
        public void setOverflow(boolean overflow) { this.overflow = overflow; }
    }
    
    /**
     * 乐观锁拦截器配置
     */
    public static class OptimisticLockConfig {
        /**
         * 是否启用乐观锁拦截器
         */
        private boolean enabled = true;
        
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
    }
    
    /**
     * 租户拦截器配置
     */
    public static class TenantConfig {
        /**
         * 租户拦截器启用模式
         * - auto: 根据 TenantModeProperties 自动检测
         * - true: 强制启用
         * - false: 强制禁用
         */
        private String enabled = "auto";
        
        public String getEnabled() { return enabled; }
        public void setEnabled(String enabled) { this.enabled = enabled; }
    }
    
    /**
     * 字段自动填充配置
     */
    public static class MetaHandlerConfig {
        /**
         * 是否启用字段自动填充
         */
        private boolean enabled = true;
        
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
    }
    
    /**
     * 数据权限拦截器配置
     */
    public static class DataScopeConfig {
        /**
         * 是否启用数据权限拦截器
         */
        private boolean enabled = true;
        
        /**
         * 是否启用调试模式（记录SQL修改日志）
         */
        private boolean debug = false;
        
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public boolean isDebug() { return debug; }
        public void setDebug(boolean debug) { this.debug = debug; }
    }
    
    // Main class Getters and Setters
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    
    public PaginationConfig getPagination() { return pagination; }
    public void setPagination(PaginationConfig pagination) { this.pagination = pagination; }
    
    public OptimisticLockConfig getOptimisticLock() { return optimisticLock; }
    public void setOptimisticLock(OptimisticLockConfig optimisticLock) { this.optimisticLock = optimisticLock; }
    
    public TenantConfig getTenant() { return tenant; }
    public void setTenant(TenantConfig tenant) { this.tenant = tenant; }
    
    public MetaHandlerConfig getMetaHandler() { return metaHandler; }
    public void setMetaHandler(MetaHandlerConfig metaHandler) { this.metaHandler = metaHandler; }
    
    public DataScopeConfig getDataScope() { return dataScope; }
    public void setDataScope(DataScopeConfig dataScope) { this.dataScope = dataScope; }
    
    @Override
    public String toString() {
        return "MybatisPlusProperties{" +
                "enabled=" + enabled +
                ", pagination=" + pagination +
                ", optimisticLock=" + optimisticLock +
                ", tenant=" + tenant +
                ", metaHandler=" + metaHandler +
                ", dataScope=" + dataScope +
                '}';
    }
}
